Release 10.1A: OpenEdge Development:
Progress 4GL Handbook
Examples: Communicating between persistent procedures
In this section, you extend the test windows to see a couple of different ways persistent procedures can communicate with one another.
![]()
To add a fill-in field to the main window to locate and manipulate one of the Order windows:
(You’ll just add code to hide or view it alternately, just to show that you can access it.)
- Open
h-OrderWin.wand add this statement to the main block to save off the Order Number in the procedure’sPRIVATE-DATAattribute:
- Open
h-CustOrderWin6.wand add a fill-in to the window. Call it iOrderWin and give it the label Show/Hide Order.- Define this
LEAVEtrigger for the new fill-in:
This trigger block walks through the persistent procedure list managed through the
SESSIONhandle. When it comes to an instance ofh-OrderWin.wwhosePRIVATE-DATAattribute matches the value in the fill-in, it saves off itsCURRENT-WINDOWattribute, which is the handle of the procedure’s window. If the window is currently hidden it is viewed, and vice versa.- Save the changes and test them out:
This is a simple example of how to use the
SESSIONprocedure list to locate a procedure you’re interested in, and then either manipulate that procedure object or make a request of it in some way.The next example goes in the opposite direction. Rather than locating one of the Order windows from the main window, you add code to the Order window procedure to request the handle of another procedure from the main window. It then uses that handle to reposition the other Order window. A new internal procedure in the main window provides an interface the Order window can use to get the handle it needs.
Using SOURCE-PROCEDURE to identify your caller
First, you’ll learn another useful built-in function. You’ve seen the
THIS-PROCEDUREhandle function, which holds the handle of the current procedure. Another similar built-in handle function isSOURCE-PROCEDURE. Whenever Progress executes aRUNstatement, theSOURCE-PROCEDUREhandle in the called procedure returns the procedure handle of the caller.
![]()
To use
SOURCE-PROCEDUREto identify your caller:
- To capture the
SOURCE-PROCEDUREwhen the Order window first starts up, add this definition to the Definitions section ofh-OrderWin.w:
- Add another line to its main block, to save off the value on start-up:
- Add a new fill-in to the window called iOtherOrder, with a Label of Other Order.
- Add a new button called BtnAlign, with a Label of Align Order.
You can put a rectangle around them to group them if you want, like this:
![]()
- Code this
CHOOSEtrigger for BtnAlign:
This code runs an internal procedure in its source (the main window), which takes an Order number as input and returns as output the handle of the window with that Order number in it. The code then uses the
CURRENT-WINDOWattribute of that other window and theCURRENT-WINDOWattribute ofTHIS-PROCEDUREto align the other window just below and to the right of this one.- In
h-CustOrderWin6.w, add another variable to the Definitions section:
This variable will hold a list of all the Order numbers the procedure opens up windows for.
- Add a statement to the BtnOrder (Order Detail) button to save off the Order number of each window as it’s created, in addition to its procedure handle:
- Define the new
fetchOrderWininternal procedure inh-CustOrderWin6.w:
This code acts as an API call that other procedures like the instances of
h-OrderWincan run to obtain data from the main window. It looks through the list of Order numbers and, when it finds the one that was requested, it passes back as output the matching procedure handle for that Order.
![]()
To test out this latest change:
Why did you use a button with a
CHOOSEtrigger instead of just defining aLEAVEtrigger for the fill-in? In this case, without the button the fill-in would be the only enabled object in the window, so itsLEAVEtrigger would not fire. You need at least two enabled objects in a window in order to leave one of them. So the button gives you something to tab into and click.This latest example shows you in simple terms how you can provide an API in a procedure that other persistent procedures can use to get information from, or to invoke actions in, and a couple of different ways to obtain the handles of other running procedures you’re interested in.
Now that you have learned the difference between non-persistent and persistent procedures, and how the stack of procedure calls in a typical older Progress application is turned into something more flexible with persistent procedures, it’s time to learn about a programming concept that was very important in those older applications, but which you won’t use often in new applications.
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |